<?php
/* 
* @Author: Jerry-chen
* @Date:   2014-07-21 23:52:57
* @Last Modified time: 2014-07-28 01:26:50
* @Last Modified by: Jerry-chen<uranusbill@163.com>
* @ Copyright (c) 2014 http://www.cooldreamer.com All rightsreserved.
*/

class ChooseseatControl extends PublicControl
{
	
	public function index()
	{
		// 得到GET传过来的ID查出商品的相关信息
		$goodsid = Q('get.goodsid');
		// p($goodsid);
		$goodsData = K('Goods')->get_one(array('goodsid'=>$goodsid));
		// p($goodsData);
		$this->assign('goodsData',$goodsData);

		//查出演出地点
		$seatid = $goodsData['seatid'];
		$seatData = K('Seat')->get_one(array('seatid'=>$seatid));
		//把查出来的座位截成数组
		$seatData['seatsort'] = rtrim($seatData['seatsort'],',');
		$seatData['seatsort'] = explode(',', $seatData['seatsort']);
		$this->assign('seatData',$seatData);
		//----查出对应时间的相应价格
		$goodstimeData = K('Goodstime')->get_one(array('goodsid'=>$goodsid),array('timeid','time'));
		// p($goodstimeData);
		$priceData = K('Goodsprice')->get_all(array('goodstimeid'=>$goodstimeData['timeid']),array('price','countticket','goodsprice','goodstimeid'));
		// p($priceData);
		$seatsort = $seatData['seatsort'];
		// 组合数组，分配价座位和价格
		// p($seatsort);
		// p($priceData);
		foreach ($priceData as $key => $value) 
		{
			$priceData[$key]['seatsort'] = $seatsort[$key]; 
	
		}
		// p($priceData);
		$this->assign('priceData',$priceData);
		//定义一个空数组，重组数组
		$price=array();
		foreach ($goodstimeData as $k => $v) {
			//得到当前的TIMEID，然后找出对应TIMEID的价格和座位
			$goodstimeData[$k]['prices'] = K('goodsprice')->get_all(array('goodstimeid'=>$v['timeid']),array('price','countticket','goodsprice'));//价格，票数，goodsprice是价格ID
		}
		// p($goodstimeData);
		$this->assign('goodstimeData',$goodstimeData);
		//运费数据
		$fareData = K('Fare')->get_all();
		$this->assign('fareData',$fareData);
		//直接购买控制器里面，SESSION里面的控制值为1
		session('step',1);
		$this->display('01.html');
	}
}